import java.util.Arrays;
import java.util.Scanner;

public class 小朋友排队 {
    static int N = 1000010;
    static int[] arr = new int[N];
    static int[] sum = new int[N];
    static int[] tree = new int[N];
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        for (int i=0;i<n;i++) {
            arr[i] = s.nextInt();
            arr[i]++;
        }

        for (int i=0;i<n;i++) {
            add(arr[i],1);
            sum[i] = query(N-1) - query(arr[i]);
        }
        Arrays.fill(tree,0);
        for (int i=0;i<n;i++) {
            add(arr[i],1);
            int a = query(arr[i]-1);
            sum[i]+=a;
            System.out.println(arr[i]+" "+a);
        }
        long end = 0;
        for (int i=0;i<n;i++) end+=((long)sum[i]+1)*sum[i]/2;
        System.out.println(end);

    }
    private static int lowBit(int x) { return x & -x;}
    private static int query(int n) {
        int sum=0;
        for (int i=n;i>0;i-=lowBit(i)) sum+=tree[i];
        return sum;
    }
    private static void add(int n,int v) {
        for (int i=n;i<N;i+=lowBit(i)) tree[i]+=v;
    }
}
